Ext.namespace("GridFiberInfo");

GridFiberInfo.Detail = function(plist){
	
	this.parentList = plist;
	
	//网络资源ID
    this.txtNrID = new Ext.form.Hidden({
    	name: 'nrId'
    });

	//光纤名称
	this.txtNrName = new Ext.form.TextField({
		fieldLabel : '光纤名称',
		name :'nrName',
		width : 200,
		allowBlank : false,
        blankText : '请输入光纤名称!'
	});
	
	//光纤位置描述
	this.txtLocationDesc = new Ext.form.TextArea({
		fieldLabel : '光纤位置描述',
		preventScrollbars: true,
		name :'locationDesc',
		width : 400
	});
	
	//资源类型
    this.txtNrType = new Ext.form.Hidden({
    	name: 'nrType',
    	value: '3'
    });
    
    //光纤ID
     this.txtFiberID = new Ext.form.Hidden({
    	name: 'fiberId'
    });
	
	//光纤长度
	this.txtFiberLength = new Ext.form.NumberField({
		fieldLabel: '光纤长度',
		name :'fiberLength',
		width: 120
	});

	//备注
	this.txtRemark = new Ext.form.TextArea({
		fieldLabel : '备注',
		preventScrollbars: true,
		name :'remark',
		width : 400
	});
	
	
	//基本信息
	this.basicForm = new Ext.form.FormPanel({
		bodyStyle : 'padding: 5px 5px 0',
		frame :true,
		//fileUpload: true, 
		autoScroll : true,
		height: 390,
		width : 700,
		labelAlign: 'right',
		labelWidth : 120,
		layout : 'table',
		layoutConfig : {columns:2},
		items:[
			{colspan:2,layout:'form',items:[this.txtNrName]},
			{colspan:2,layout:'form',items:[this.txtLocationDesc]},
			{layout:'form', items:[this.txtNrType]},
            {layout:'form', items:[this.txtFiberLength]},
            {colspan:2,layout:'form',items:[this.txtRemark]},
            {colspan:2,layout:'form',items:[this.txtNrID]},
            {colspan:2,layout:'form',items:[this.txtFiberID]}
		]
	});
	
	//GIS信息
	this.txtGisId = new Ext.form.Hidden({
		name: 'gisInfo.id'
	});
	
	this.txtGisType = new Ext.form.Hidden({
		name: 'gisInfo.type',
		value: 3
	});
	//片区属地
	this.cmbDistrictList = new Ext.form.ComboBox({
        width: 150,
        listWidth:167,
        fieldLabel: '片区属地',
        name : 'gridId',
        store : new Ext.data.JsonStore({
		   url:"../gridareas/listAllDistricts.form",
		   autoLoad : true,
		   root:"districts",
		   fields:["areaId","name"]
		}),
		valueField : 'areaId',
		displayField :'name',
        mode: 'local',
        emptyText:'',
        triggerAction: 'all',
        selectOnFocus: true
    });
    
    //光纤坐标
    this.txtFiberCoordsInfo = new Ext.form.TextArea({
		fieldLabel : '光纤坐标',
		preventScrollbars : true,
		name :'coordsInfo',
		width : 400,
		heigth : 350
    });
    
    //光纤颜色
    this.txtLineColor = new Ext.form.Hidden({
    	name: 'lineColor'
    });
    
    //光纤粗细
    this.txtLineWidth = new Ext.form.Hidden({
    	name: 'lineWidth'
    });
    
    //光纤样式
    this.txtLineStyle = new Ext.form.Hidden({
    	name: 'lineStyle'
    });
    
    //绘制光纤
    this.btnDrawFiber = new Ext.Button({
        text: '绘制光纤',
        tooltip: {text: '绘制光纤'},
        handler: this.viewGis,
        scope: this
    });
    
    //GIS信息--FormPanel
    this.gisform = new Ext.form.FormPanel({
		bodyStyle : 'padding: 5px 5px 0',
		frame :true,
		height:420,
		width : 700,
		labelAlign: 'right',
		labelWidth : 120,
		layout : 'table',
		layoutConfig : {columns:2},
		items:[
			{colspan:2,layout:'form',items:[this.cmbDistrictList]},
			{colspan:2,layout:'form', items:[this.txtFiberCoordsInfo]},
            {layout:'form', items:[this.txtLineColor]},
            {layout:'form', items:[this.txtLineWidth]},
            {layout:'form', items:[this.txtLineStyle]},
            {colspan:2,layout:'form', items:[this.btnDrawFiber]},
            {layout:'form', items:[this.txtGisId]}
		]
	});
		
	 this.tabs = new Ext.TabPanel({
        width:700,
        activeTab: 0,
        frame:true,
        height : 420,
        deferredRender:false, 
		layoutOnTabChange:true,
		
        items:[
            {items:this.basicForm, title: '基本信息'},
            {items:this.gisform, title: 'Gis信息'}      
        ]
    });
    
	GridFiberInfo.Detail.superclass.constructor.call(this,{
		title : '光纤信息',
		bodyStyle: 'padding: 5px 5px 0',
        autoHeight: true,
        width: 730,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items :[this.tabs],
        buttons: [{
            text: '保存',
            cls: 'x-btn-text-icon btn-save',
            handler: this.onSave,
            scope: this
        }, {
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
		
	});
	this.connSave = new Ext.data.Connection({
		url: '../gridnetworkresource/save.form?timesnap=' + Date.parse(new Date()),
		method: 'POST'
	});
};

Ext.extend(GridFiberInfo.Detail,Ext.Window,{
	initData : function(id) {
			this.basicForm.getForm().reset();
			this.gisform.getForm().reset();
			var connection = new Ext.data.Connection({
						url : '../gridnetworkresource/prepare.form?timesnap=' + Date.parse(new Date()),
						method : 'POST'
					});
			if(id!=null){
				Utils.request(connection, {
						params : {
							nrId : id
						},
						scope : this,
						success : function(resp, action) {
							var nr = resp.gridNetworkResource;
							var gf = resp.gridFiberInfo;
							var gis = resp.gisInfo;
							
							//console.info(obj);
							
							//网络资源ID
							this.scope.txtNrID.setValue(nr.nrId);
							//光纤名称
							this.scope.txtNrName.setValue(nr.nrName);
							//光纤位置描述
							this.scope.txtLocationDesc.setValue(nr.locationDesc);
							//资源类型
							this.scope.txtNrType.setValue(nr.nrType);
							//光纤ID
							this.scope.txtFiberID.setValue(gf.fiberId);
							//光纤长度
							this.scope.txtFiberLength.setValue(gf.fiberLength);
							//备注
							this.scope.txtRemark.setValue(gf.remark);
							
							//片区ID
							this.scope.cmbDistrictList.setValue(nr.distId);
							
							//GisId
							this.scope.txtGisId.setValue(gis.id);
							
							//光纤坐标
							this.scope.txtFiberCoordsInfo.setValue(gis.coordsInfo);
							//光纤颜色
							this.scope.txtLineColor.setValue(gis.lineColor);
							//光纤粗细
							this.scope.txtLineWidth.setValue(gis.lineWidth);
							//光纤样式
							this.scope.txtLineStyle.setValue(gis.lineStyle);
						},
						after : function() {					
						}
					});
			}
		},
		onSave: function(btn, event) {
			var form =this.basicForm.getForm();
			if (!form.isValid()) {
				return;
			}
			form.doAction('submit', { 
				method : 'post',
				url : '../gridnetworkresource/save.form', 
				params: {
					'distId' : this.cmbDistrictList.getValue(),
					'gisInfo.coordsInfo' : this.txtFiberCoordsInfo.getValue(),
					'gisInfo.lineColor' : this.txtLineColor.getValue(),
					'gisInfo.lineWidth' : this.txtLineWidth.getValue(),
					'gisInfo.lineStyle' : this.txtLineStyle.getValue(),
					'gisInfo.type' : this.txtGisType.getValue(),
					'gisInfo.id' : this.txtGisId.getValue()
				},
				scope: this,
				success: function(form, action) {
					//console.info(this);
					this.parentList.update();
					this.hide();
				},
				after: function() {}
			});
	},
		
		initGis:function(lineColor, lineWidth, lineStyle, lineText,coordInfo){
			
			//alert(lineColor+lineWidth+lineStyle+lineText+coordInfo);
			
			this.txtLineColor.setValue(lineColor);
			this.txtLineWidth.setValue(lineWidth);
			this.txtLineStyle.setValue(lineStyle);
			this.txtNrName.setValue(lineText);
			this.txtFiberCoordsInfo.setValue(coordInfo);
		},
		
		viewGis:function(){
			
			var did = this.cmbDistrictList.getValue();
			if(did==''){
				Utils.warn('请先选择片区！');
				return;
			}
			
			var str = OMS.GIS_IP+'/gis_for_management.jsp?did=' + this.cmbDistrictList.getValue() + 
			'&lineColor=' + this.txtLineColor.getValue() + 
			'&lineWidth=' + this.txtLineWidth.getValue() + 
			'&lineStyle='+this.txtLineStyle.getValue()+ 
			'&name='+this.txtNrName.getValue()+
			'&type='+this.txtGisType.getValue()+ 
			'&coordx='+this.txtFiberCoordsInfo.getValue();
			window.open(encodeURI(str), '_blank', 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,width=1000,height=600,resizable=no,left=0,top=0, status=no');	
		}
});
